
$(function() {
	
	$("input[id^='mold_s']:visible").autocomplete(Test.mold);
	
	$("input[id^='worker_s']:visible").autocomplete(Test.emp);
	
	Tip.emp('负责人');
});

var Work = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_add")[0];

				var body = { };
				body.mold = form.mold.value;
				body.plan = form.plan.value;
				body.type = form.type.value;
				body.t1 = form.date1.value + " " + form.time1.value;
				body.t2 = form.date2.value + " " + form.time2.value;
				
				body.worker = form.worker.value;
				body.machine = form.machine.value;

				body.content = form.content.value;

				$(this).dialog("close");

				$.post('mold.php?do=Work.addPost', body, function(data) {
					// $(result).html(data);
					Common.ret_add(data);
				}, "json");
			}
		});		

		dialog_add(url, title, xy);
	},
	
	dialog_batch_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_add")[0];

				var body = { };
				body.type = form.type.value;
				body.t1 = form.date1.value + " " + form.time1.value;
				body.t2 = form.date2.value + " " + form.time2.value;
				
				body.content = form.content.value;
				
				// body.item = data;
				body.item = $.toJSON(data);

				$(this).dialog("close");

				$.post('mold.php?do=Work.batchPost', body, function(data) {
					// $(result).html(data);
					Common.ret_add(data);
				}, "json");
			}
		});		

		dialog_add(url, title, xy);
	},
	
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		$.cookie('status_', status);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'mold.php?do=Work.edit&id=' + id;
		var c2 = 'mold.php?do=Work.view&id=' + id;
		var c3 = 'mold.php?do=Work.copy&id=' + id;

		var a1 = ['编辑信息', 'url', 'Work.dialog_edit_', '600x380'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '600x380'];
		var a3 = ['复制信息', 'url', 'Work.dialog_copy_', '650x380'];

		var s = c1 + ", " + c2 + ", " + c3;

		return popup(e, [a1, a2, a3], s);
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭" : function() {
				$(this).dialog("close");
			},

			"修改" : function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_edit")[0];

				var body = {};
				body.id = form.id.value;
				body.mold = form.mold.value;
				body.plan = form.plan.value;
				body.type = form.type.value;
				body.t1 = form.date1.value + " " + form.time1.value;
				body.t2 = form.date2.value + " " + form.time2.value;
				
				body.worker = form.worker.value;
				body.machine = form.machine.value;

				body.content = form.content.value;
				
				$(this).dialog("close");

				var url = 'mold.php?do=Work.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},

	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭" : function() {
				$(this).dialog("close");
			},

			"复制" : function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_add")[0];

				var body = {};
				body.mold = form.mold.value;
				body.plan = form.plan.value;
				body.type = form.type.value;
				body.t1 = form.date1.value + " " + form.time1.value;
				body.t2 = form.date2.value + " " + form.time2.value;
				
				body.worker = form.worker.value;
				body.machine = form.machine.value;

				body.content = form.content.value;
				
				$(this).dialog("close");

				$.post('mold.php?do=Work.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_add(url, title, xy);
	},

	list_continue: function (url, view) {
		if (confirm("电脑是否维修好？")) {
			list(url, view);
		}
	},

	list_idle: function (url, view) {
		if (confirm("电脑是否空闲？")) {
			list(url, view);
		}
	},

	/**
	 * 暂停
	 */
	dialog_edit_stop: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭" : function() {
				$(this).dialog("close");
			},

			"提交" : function() {
				if (!confirm("确认是否维修？")) {
					return false;
				}

				var form = $("#form_edit")[0];
				var body = {};

				body.reason = form.reason.value;
				body.status = 3;

				$(this).dialog("close");

				var url = 'info.php?do=Computer.reasonPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},

	/**
	 * 取消
	 */
	dialog_edit_cancel: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭" : function() {
				$(this).dialog("close");
			},

			"提交" : function() {
				if (!confirm("确认是否报废？")) {
					return false;
				}

				var form = $("#form_edit")[0];
				var body = {};

				body.reason = form.reason.value;
				body.status = 9;

				$(this).dialog("close");

				var url = 'info.php?do=Computer.reasonPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},

	plan: function (id) {
		var url = "mold.php?do=Plan.view&id=" + id;
		$('#dialog_view').dialog('option', 'buttons', { 		
			"关闭": function() { 
				$(this).dialog("close");
			}
		});

		dialog_view(url, '计划信息', '600x400');
	},
	
	popup_all: function (e, p2) {
		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'mold.php?do=Work.delete' + p2;
		var c2 = 'mold.php?do=Work.xls' + p2;
			
		var a1 = ['删除信息', 'url', 'Common.list_delete'];
		var a2 = ['导出Excel', 'url', 'jswin', '1024x768'];

		var s = c1 + ", " + c2;

		return popup(e, [a1, a2], s);
	}
};
